<?php
    function fileUpload($path,$filesize,$upfile,$arr = array())
    {
        $path = rtrim($path,"/")."/";
        
        if($upfile['error'] > 0) {
            switch($upfile['error']) {
                case 1:
                    $info = "1";
                break;
                case 2:
                    $info = "2";
                break;
                case 3:
                    $info = "3";
                break;
                case 4:
                    $info = "4";
                break;
                case 6:
                    $info = "6";
                break;
                case 7:
                    $info = "7";
                break;
                default:
                    $info = "未知错误";
            }
            return $info;
        }
        
        if($filesize > 0 && $filesize < $upfile['size']) {
            $info = "文件过大";
            return $info;
        }
        
        $filetype = $upfile['type'];
        if(!in_array($filetype,$arr)) {
            $info = "文件格式不正确";
            return $info;
        }
        
        $hou = pathinfo($upfile['name'],PATHINFO_EXTENSION);
        do{
            $filename = md5(date(YmdHis).rand(0,999)).".".$hou;
        }while(file_exists($filename));
        
        if(move_upfloaded_file($upfile['tmp_name'],"./{$path}/{$filename}")) {
            $info = "文件上传成功";
        }
        return $info;
    }
    
    
    
    
    
    
    
    